---
layout: "default"
title: "LosslessStringConvertible"
description: "Swift documentation for 'LosslessStringConvertible': A type that can be represented as a string in a lossless, unambiguous way."
keywords: "LosslessStringConvertible,protocol,swift,documentation,description"
root: "/v3.1"
---

<div class="intro-declaration"><code class="language-swift">protocol LosslessStringConvertible</code></div>

<div class="discussion comment">
    <p>A type that can be represented as a string in a lossless, unambiguous way.</p>

<p>For example, the integer value 1050 can be represented in its entirety as
the string &quot;1050&quot;.</p>

<p>The description property of a conforming type must be a value-preserving
representation of the original value. As such, it should be possible to
re-create an instance from its string representation.</p>
</div>

<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">CustomStringConvertible</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_">init?(<wbr>_:)</a> <span class="required">Required</span><div class="comment collapse" id="comment-init_"><div class="p">
    <p>Instantiates an instance of the conforming type from a string
representation.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ description: String)</code>

    </div></div>
</div>


<h3>Instance Variables</h3>
<div class="declaration inherited" id="var-description_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-description_-string">var description: String</a> <span class="required">Required</span><div class="comment collapse" id="comment-var-description_-string"><div class="p">
    <p>A textual representation of this instance.</p>

<p>Instead of accessing this property directly, convert an instance of any
type to a string by using the <code>String(describing:)</code> initializer. For
example:</p>

<pre><code class="language-swift">struct Point: CustomStringConvertible {
    let x: Int, y: Int

    var description: String {
        return &quot;(\(x), \(y))&quot;
    }
}

let p = Point(x: 21, y: 30)
let s = String(describing: p)
print(s)
// Prints &quot;(21, 30)&quot;</code></pre>

<p>The conversion of <code>p</code> to a string in the assignment to <code>s</code> uses the
<code>Point</code> type&#39;s <code>description</code> property.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var description: String { get }</code>

        <h4>Declared In</h4>
            <a href="../../protocol/CustomStringConvertible/"><code>CustomStringConvertible</code></a>
        </div></div>
</div>





